const {
  http
} = require("../../../../utils/apiutils")

Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: {
      name: "",
      bankCard: "",
      bankName: "",
    },
    isF: false,
    isB:false,
  },
  bindinputName: function (e) {
    console.log("-----------", e);
    this.data.info.name = e.detail.value;
    this.nextPush()
  },
  bindinputcard: function (e) {
    this.data.info.bankCard = e.detail.value;
    this.nextPush()
  },
  bindinputbank: function (e) {
    this.data.info.bankName = e.detail.value;
    this.nextPush()
  },
  nextPush: function () {
    if (this.data.info.name.length > 0 && this.data.info.name.length < 20) {
      if (this.data.info.bankCard.length > 10 && this.data.info.bankCard.length < 20) {
        if (this.data.info.bankName.length > 2) {
          this.setData({
            isF: true
          })
          return;
        }
      }
    }
    this.setData({
      isF: false,
    })

  },
     //获取用户信息
     getuser: function () {

      var that = this;
      wx.showLoading({
        title: '加载中...',
      })
      http.userInfo({},
        function (res) {
          wx.hideLoading()
          console.log("------用户信息--", res);
          if (res.code == 0) {
            getApp().globalData.userInfo = res.data;
          } else {
            wx.showToast({
              title: res.message,
              icon: "none",
            })
          }
        },
        function (err) {
          wx.hideLoading()
        })
  
    },

  onclickSumbit: function () {
    if (!this.data.isF) {
      wx.showToast({
        title: '请输入完整信息后提交',
        icon: "none"
      })
    } else {
      var that = this;
      wx.showLoading({
        title: '加载中...',
      })
      http.bankCard(this.data.info,
        function (res) {
          wx.hideLoading()
          if (res.code == 0) {
            that.getuser();
            wx.showModal({
              title: "提示",
              content: "您已成功绑定银行卡",
              showCancel: false,
              confirmText: "我知道了",
              success: function () {
                wx.navigateBack({
                  delta: 2,
                })
              }
            })
            // wx.navigateTo({
            //   url: 'url',
            //   events: events,
            //   success: (result) => {},
            //   fail: (res) => {},
            //   complete: (res) => {},
            // })

          } else {
            wx.showToast({
              title: res.message,
              icon: "none",
            })
          }
        },
        function (err) {
          wx.hideLoading()
        })


    }

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    let userInfo = getApp().globalData.userInfo;
    if(userInfo.bankCard != "")
    {
      this.setData({
        isB:true,
        userInfo:userInfo,
        
      })
    }


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var shareObj = {
      title: "分享岗位", // 默认是小程序的名称(可以写slogan等)
      path: getApp().globalData.userInfo.inviteCode?'/pages/index/index?code='+getApp().globalData.userInfo.inviteCode:'/pages/index/index', // 
      imageUrl: '',
      success: function (res) {
        // 转发成功之后的回调
        if (res.errMsg == 'shareAppMessage:ok') {
        }
      }
    }
    console.log("------------", shareObj);
    // 返回shareObj
    return shareObj;
  }
})